package ee.graphicscard.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CommandDescriptionFinder 
{
	
	public String findCommandDescriptionFromRequest(HttpServletRequest request, HttpServletResponse response)
	{
		String commandFound = "default"; //praegu default findAll()
		
		try
		{
			if (request.getParameter("id") != null)
			{
				if (isInteger(request.getParameter("id")))
				{
					commandFound = "show_graphics_card_by_id";
				}
			}
			else if (request.getParameter("action") != null)
			{
				if (request.getParameter("action").equals("save"))
				{
					commandFound = "save_graphics_card_update";
				}
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		
		return commandFound;
	}
	
	
	public static boolean isInteger(String stringToCheck) 
	{
	    try 
	    { 
	        Integer.parseInt(stringToCheck); 
	    }
	    catch(NumberFormatException e) 
	    { 
	        return false; 
	    }
	    
	    return true;
	}
}